<template>
    <rx-layout>
        <div slot="center" style>
            <rx-fit :isheader="isheader">
                <div slot="toolheader" border="false" foldbtn='false'>
                    <div class="table-operator">
                        <a-button type="primary" icon="plus" @click="add">{{$ti18('rxList.newBtn','新建')}}</a-button>
                        <a-dropdown v-show=" selectedRowKeys.length > 0">
                            <a-button type="danger" icon="delete" @click="delByIds(selectedRowKeys)">{{$ti18('rxList.delBtn','删除')}}</a-button>
                        </a-dropdown>
                    </div>
                    <span class="search-btn-box" v-if="!isheader">
            <span class="search-btn" @click.stop="searchshow"><i class="iconfont iconguolv"></i>{{$ti18('rxList.leachBtn','过滤')}}</span>
          </span>
                </div>
                <div btnalign="right" slot="searchbar" v-if="fitSearch" @search="search" @cancel="cancel"
                     @close="closeSearchbar">
                    <a-form :layout="colLayout">
                        <a-row :gutter="24">
                            <a-col :span="colSpan">
                                <a-form-item :label="i18n('form.nameCn','公司中文名')">
                                    <a-input :placeholder="i18n('form.nameCn','公司中文名','input')" v-model="queryParam.Q_NAME_CN__S_LK"/>
                                </a-form-item>
                            </a-col>
                            <a-col :span="colSpan">
                                <a-form-item :label="i18n('form.domain','公司域名')">
                                    <a-input :placeholder="i18n('form.domain','公司域名','input')" v-model="queryParam.Q_DOMAIN__S_LK"/>
                                </a-form-item>
                            </a-col>
                        </a-row>
                    </a-form>
                </div>
                <rx-grid
                    ref="table"
                    :bordered="isBorder"
                    :allowRowSelect="true"
                    :multiSelect="true"
                    :columns="columns"
                    :defaultPageSize="10"
                    url="/api-user/user/org/osInst/query"
                    :queryParam="queryParam"
                    data-field="result.data"
                    :pageSizeOptions="['10','30','40']"
                    id-field="instId"
                    @selectChange="onSelectChange"
                >
                  <span slot="typeName" slot-scope="{ text }">
                      {{$i18(text,"租户类型名称")}}
                  </span>
                    <span slot="status" slot-scope="{ text }">
                    <a-tag :color="statusMap[text].color">
                      <span>{{ statusMap[text].text }}</span>
                    </a-tag>
                  </span>
                    <span slot="action" slot-scope="{ text, record }" class="actionIcons">
                    <span @click.stop="edit(record)">{{$ti18('rxList.editBtn','编辑')}}</span>
                        <span @click.stop="delByIds([record.instId])" v-if="record.instId!='1'">{{$ti18('rxList.delBtn','删除')}}</span>
                        <span v-if="record.status=='ENABLED'&&record.instId!='1'" @click.stop="groupManager(record)" :title="i18n('list.osInstManage','组织机构管理')">{{i18n('list.osInstManage','组织机构管理')}}</span>
                        <span v-if="record.status=='ENABLED'" @click.stop="adminManager(record)" :title="i18n('list.adminManage','管理员管理')">{{i18n('list.adminManage','管理员管理')}}</span>
                        <span v-if="record.status=='ENABLED'" @click.stop="setBpmAdminGroup(record)" :title="i18n('list.setManage','设置流程管理员组')">{{i18n('list.setManage','设置流程管理员组')}}</span>
                       </span>
                </rx-grid>

            </rx-fit>
        </div>
    </rx-layout>
</template>

<script>
import OsInstApi from '@/api/user/org/osInst'
import OsInstEdit from './OsInstEdit.vue'

import {BaseList, RxLayout, RxGrid, RxFit, Util , TabOpen} from "@lowcode/jpaas-common-lib"
import OsInstAdmin from "./OsInstAdmin";
import OsInstSetBpmAdminGroup from "./OsInstSetBpmAdminGroup";

export default {
    name: 'TableList',
    components: {
        OsInstEdit,
        RxLayout,
        RxGrid,
        RxFit
    },
    mixins: [BaseList,TabOpen],
    data() {
        return {
            formd: this.$form.createForm(this),
            // 查询参数
            queryParam: {},
            // 表头
            columns: [

                {
                    title: this.i18n('form.nameCn','公司中文名'),
                    dataIndex: 'nameCn',//i18n('form.nameCn','公司中文名')
                    width: 160
                },
                {
                    title: this.i18n('form.instNo','租户编号'),
                    dataIndex: 'instNo',
                    width: 160
                },
                {
                    title: this.i18n('form.typeName','租户类型'),
                    dataIndex: 'typeName',
                    scopedSlots: {customRender: 'typeName'},
                    width: 160
                },
                {
                    title: this.i18n('form.domain','域名'),
                    dataIndex: 'domain',
                    width: 100
                },
                {
                    title: this.i18n('form.status','状态'),
                    dataIndex: 'status',
                    scopedSlots: {customRender: 'status'},
                    width: 160
                },
                {
                    title: this.i18n('form.createTime','创建时间'),
                    dataIndex: 'createTime',
                    width: 160
                },
                {
                    title: this.$ti18('rxList.action','操作'),
                    width: 180,
                    dataIndex: 'action',
                    scopedSlots: {customRender: 'action'}
                },
            ],
            component: OsInstEdit,
            comment: this.i18n('list.instList','租户列表'),
            statusMap: {
                ENABLED: {color: 'green', text: this.i18n('statusMap.ENABLED','启用')},
                DISABLED: {color: 'red', text: this.i18n('statusMap.DISABLED','禁用')},
                INIT: {color: 'orange', text: this.i18n('statusMap.INIT','初始化')},
            },

        }
    },
    methods: {
        //一开始调用数据
        getListByParams(parameter) {
            return OsInstApi.query(parameter)
        },
        i18n(name,text,key){
            return this.$ti18(name,text,"osInst",key);
        },
        delById(ids) {
            return OsInstApi.del({ids: ids.join(',')})
        },
        search() {
            this.$refs.table.loadData();
        },
        cancel() {
            this.resetSearch();
        },
        closeSearchbar() {
            //关闭过滤弹窗；（点击X触发）
            this.fitSearch = false;
        },
        groupManager(record) {
            let config = {
                title:this.i18n('list.osInstManage','组织机构管理'), //页面名称 必填
                key:'osGroupList',//页面路由name  必填
                params:{//页面传参 可选
                    tenantId:record.instId,
                    instType:record.instType,//机构类型Id
                },
                showType:"URL",
                component:'modules/user/org/OsGroupList'
            }
            this.openTabs(config);
            //this.$router.push({name: 'osGroupList', params: {tenantId: record.instId}});
        },
        adminManager(record) {
            var params = {tenantId: record.instId};
            var conf = {
                curVm: this,
                shade: false,
                data: params,
                widthHeight: ['800px', '600px'],
                component: OsInstAdmin,
                title: "[" + record.nameCn + ']' + this.i18n('list.adminManage','管理员管理')
            };
            Util.open(conf, function (action) {
            });
        },
        setBpmAdminGroup(record){
            var params = {pkId: record.instId};
            var conf = {
                curVm: this,
                shade: false,
                data: params,
                widthHeight: ['400px', '200px'],
                component: OsInstSetBpmAdminGroup,
                title: "[" + record.nameCn + ']' + this.i18n('list.setManage','设置流程管理员组')
            };
            Util.open(conf, function (action) {
            });
        }
    }

}
</script>
